package com.base.cn.platform.os.controller.web.help;

import com.base.cn.platform.os.common.WebBaseController;
import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.service.manage.help.SysHelpCenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 前台帮助中心Controller
 *
 * @author s.li
 * @create 2018-08-22-15:13
 */
@Controller
@RequestMapping("/web/help")
public class WebHelpController extends WebBaseController {

    @Autowired
    private SysHelpCenterService sysHelpCenterService;

    /**
     * 帮助中心
     * @param model
     * @return 页面
     */
    @RequestMapping("/index")
    public String helpIndex(Model model,
                            @RequestParam(value = "id",required = false, defaultValue = "0")BigDecimal id){
        Map<String,Object> params = new HashMap<>();
        params.put("status",1);
        params.put("showClients",2);
        List<Map<String,Object>> helpList = sysHelpCenterService.findPageHelpList(params,false);
        model.addAttribute("helpList",helpList);
        model.addAttribute("showId",id);
        return resultPage("/help/web-help");
    }

    /**
     * 显示内容
     * @param helpId 帮助文档ID
     * @return Map<String,Object>
     */
    @RequestMapping("/showContext")
    @ResponseBody
    public Map<String,Object> showContext(@RequestParam("helpId") BigDecimal helpId){
        Map<String,Object> helpCenter = sysHelpCenterService.findHelpCenterById(helpId);
        return ResultUtil.SUCCESS(helpCenter);
    }
}
